<template>
  <div >
    <div class="login-container">
      <el-card class="login-card">
        <h2 class="login-title">账户登录</h2>
        <el-form ref="loginForm" :model="loginForm" :rules="rules" label-position="left">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" class="login-btn" @click="handleLogin">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <div align="center">
      <a href="#">关于我们</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">联系我们</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">联系客服</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">商家入驻</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">营销中心</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">手机东东商城</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">销售联盟</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="#">东东商城社区</a> &nbsp;&nbsp;&nbsp;&nbsp;  <br/><br/>
      <span>地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</span> <br/>
      <span>京ICP备08006666号京公网安备11010888888</span>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {if (valid) {          // 这里可以进行登录逻辑，例如发送请求到后端验证用户信息          this.$message.success('登录成功');

         // 发送登录请求
         this.$http.post("/login/adminLogin",{username:this.loginForm.username,password: this.loginForm.password})
             .then(resp=>{
              var result = resp.data;

              if(result.code=="2"){
                var token = result.data;
                //存入localstorage
                localStorage.setItem("token",token);
                this.$message({
                  message: '登陆cg',
                  type: 'success'
                });
                this.$router.push("/");
              }else{
                alert(result.message);
              }

             }).catch(function (resp){
                alert("网络异常，稍后重试");
         })

      } else {
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60vh;
  background-color: #f5f5f5;
  background-image: url('@/assets/img/manage-bg.png'); /* 替换为你的图片路径 */
}

.login-card {
  width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
}

.login-btn {
  width: 100%;
}

</style>